package com.shoe.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shoe.mapper.ShoeDepotMapper;
import com.shoe.pojo.ShoeDepot;
import com.shoe.pojo.ShoeDepotExample;
import com.shoe.service.ShoeDepotService;
import com.shoe.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoeDepotServiceImpl implements ShoeDepotService {
    @Autowired
    ShoeDepotMapper shoeDepotMapper;

    @Override
    public ResponseResult selectAll(int currPage, int pageSize) {
        PageHelper.startPage(currPage,pageSize);
        List< ShoeDepot > list = shoeDepotMapper.selectByExample(null);
        PageInfo<ShoeDepot> pageInfo = new PageInfo<>(list);
        pageInfo.setNavigatePages(10);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(pageInfo);
        return responseResult;
    }

    @Override
    public ResponseResult selectByTime(int currPage, int pageSize, ShoeDepotExample example) {
        PageHelper.startPage(currPage,pageSize);
        List< ShoeDepot > list = shoeDepotMapper.selectByExample(example);
        PageInfo<ShoeDepot> pageInfo = new PageInfo<>(list);
        pageInfo.setNavigatePages(10);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setData(pageInfo);
        return responseResult;
    }

    @Override
    public List<ShoeDepot> selectByGoodId(ShoeDepotExample example) {
        return shoeDepotMapper.selectByExample(example);
    }

    @Override
    public int delById(Long depotId) {
        return shoeDepotMapper.deleteByPrimaryKey(depotId);
    }

    @Override
    public int updateByPrimaryKeySelective(ShoeDepot record) {
        return shoeDepotMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int insertSelective(ShoeDepot record) {
        return shoeDepotMapper.insertSelective(record);
    }

    @Override
    public int selectBySize(ShoeDepot shoeDepot) {
        ShoeDepotExample shoeDepotExample = new ShoeDepotExample();
        shoeDepotExample.createCriteria().andDepotGoodSizeEqualTo(shoeDepot.getDepotGoodSize()).andDepotGoodIdEqualTo(shoeDepot.getDepotGoodId());
        List<ShoeDepot> a = shoeDepotMapper.selectByExample(shoeDepotExample);
        if(a.size()>0 && a.get(0).getDepotGoodCount() > 0){
            return 1;
        }
        return 0;
    }

    @Override
    public int updateByExampleSelective(ShoeDepot record, ShoeDepotExample example) {
        return shoeDepotMapper.updateByExampleSelective( record, example);
    }
}
